{extends file='layout/admin.html'}

{block name='title'}Manage Assets  - Geek-Zoo CMS{/block}

{block name='content'}

<script type="text/javascript" src="js/asset_search.js"></script>

{if $is_my_asset}
{$url = 'my_asset'}
{else}
{$url = 'asset_manage'}
{/if}

<form action="admin/{$url}.html" method="get">
<input type="hidden" name="ids" />
<div class="clearfix sub_nav">
	{if $smarty.get.cate_id!=4 && $smarty.get.cate_id!=3}
	<span class="btn fr"><a href="admin/{$url}/add.html?cate_id={$smarty.get.cate_id}&lang={$smarty.get.lang}">Add</a></span>
	{/if}
	<input type="text" class="input_text w290" name="q" value="{$smarty.get.q}" />
	<input type="hidden" name="cate_id" value="{$smarty.get.cate_id}">
	<input type="hidden" name="lang" value="{$smarty.get.lang}">
	<input type="submit" class="btn" value="Search" />
	<div id="tags_bag" class="clearfix pt10">
	{if isset($smarty.get.ids)}
		{foreach array_filter(explode(',', $smarty.get.ids)) as $val}
			<span><a>X</a>{get_info(tags, $val, tag_name)}<input type="hidden" value="{$val}" /></span>
		{/foreach}
	{/if}
	</div>
	<script type="text/javascript" charset="utf-8">
	 $('#s_tags').click(function(){
	   var ids = [];
	   $('#tags_bag input').each(function(){
       ids.push(this.value);
     });
	   asset_search(ids, function(tags){
	     $('#tags_bag').empty();
	     $(tags).each(function(){
	       $('#tags_bag').append('<span><a href="#">X</a>'+this.name+'<input type="hidden" value="'+this.id+'" /></span>');
	     });
	   });
     
	   return false;
	 });

	 $('#tags_bag a').live('click', function(){
	   $(this).parent().remove();
	   return false;
	 });

   $('form').submit(function(){

     var ids = [];
	   $('#tags_bag input').each(function(){
       ids.push(this.value);
     });
     $('input[name=ids]').val(ids.join(','));

     return true;
   });

	</script>
</div>

</form>
	
	
<script type="text/javascript" charset="utf-8">
	var availableTags = [];

	{foreach $tags as $val}
	  {foreach $val as $v}
	    availableTags.push('{$v.tag_name}');
		{/foreach}
	{/foreach}


	$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
		  var self = this;
	    $.each( items, function( index, item ) {
	      if (index < 10) {
	        self._renderItem( ul, item );
	      }
			});
		}
	});

	$( "input[name=q]" ).catcomplete({
		source: availableTags
	});
	
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content_table">
	<thead>
		<tr style="height: 30px;">
			<th class="left" style="width: 50%;">Title</th>
			<th style="border-left: 1px solid #CCC; width: 10%; line-height: 30px;">Date Added</th>
			<th style="border-left: 1px solid #CCC; width: 15%; line-height: 30px;">Created By</th>
			<th class="right" style="border-left: 1px solid #CCC; width: 15%; line-height: 30px;" >Action</th>
		</tr>
	</thead>
	<tbody class="text_indent">
		{foreach $data as $val}
		{if $val@iteration % 2}<tr>{else}<tr class="odd" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #EEE; background-position: initial initial; background-repeat: initial initial; ">{/if}
			<td><a href="admin/{$url}/view.html?id={$val.id}">{$val.title}</a></td>
			<td style="border-right-style: none; border-right-width: initial; border-right-color: initial;">{date('m/d/Y', $val.add_time)}</td>
			<td style="border-right-style: none; border-right-width: initial; border-right-color: initial;">{get_user($val.user_id, full_name)}</td>
			<td style="border-right-style: none; border-right-width: initial; border-right-color: initial; text-align: center;">
				<a href="#">Select Actions <img src="images/i.gif" alt="Action menu" class="arrow" /></a>
				<div class="action_btn" style="display: none;">
					<ul class="action_menu">
						<li><a href="admin/{$url}/edit.html?id={$val.id}">Edit</a></li>
						{if $val.id!=26 && $val.id!=27 && $val.id!=28 && $val.id!=29}
							{if $smarty.get.cate_id!=4 && $smarty.get.cate_id!=3}
									<li><a href="admin/{$url}/delete.html?id={$val.id}" class="delete">Delete</a></li>
							{/if}
						{/if}
						
					</ul>
				</div>
			</td>
		</tr>
		{/foreach}
	</tbody>
</table>
<div class="clearfix sub_nav">
{include file="lib/admin_pager.html"}
{if $smarty.get.cate_id!=4 && $smarty.get.cate_id!=3}
<span class="btn fr"><a href="admin/{$url}/add.html?cate_id={$smarty.get.cate_id}&lang={$smarty.get.lang}">Add</a></span>
{/if}
</div>
<script type="text/javascript" charset="utf-8">
// show_msg confirm('sssss?',functio(){
	//ssss
// })

$('.arrow').each(function(){
  $(this).parent().popup($(this).parent().next());
});

$(".delete").click(function(){
	  var url = this.href;
		confirm('Are you sure to delete this?', function(){
	    location.href = url;
		});
		return false;
});
</script>
{/block}
